package PTA_JAVA.Exception6.demo3;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        double[] arr = new double[n];
        for (int i = 0; i < n; i++) {
            arr[i]= Double.parseDouble(sc.next());
        }
        sc.nextLine();
        while(sc.hasNextLine()){
            String s = sc.nextLine();
            if("end".equals(s)){
                break;
            }
            String[] str = s.split(" ");
            int begin= Integer.parseInt(str[0]);
            int end = Integer.parseInt(str[1]);
            try {
                System.out.println(ArrayUtils.findMax(arr, begin,end));
            } catch (Exception e) {
                System.out.println(e);
            }
        }
        try {
            System.out.println(ArrayUtils.class.getDeclaredMethod("findMax", double[].class,int.class,int.class));
        } catch (Exception e1) {
        }
    }
}
class ArrayUtils{
    public static double findMax(double[] arr,int begin, int end)throws IllegalArgumentException{
        double max=arr[0];
        if(begin>=end){
            throw new IllegalArgumentException("begin:"+begin+" >= end:"+end);
        }else if(begin<0){
            throw new IllegalArgumentException("begin:"+begin+" < 0");
        }else if(end>arr.length){
            throw new IllegalArgumentException("end:"+end+" > arr.length");
        }else{
            for (int i = begin; i <end; i++) {
                if(max<arr[i]){
                    max = arr[i];
                }
            }
        }
        return max;
    }
}
